﻿<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
    <link href="../lib/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
<script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>自加工处理</title>
</head>
<body>

    <div class="pd-5">
        <div class="row cl" id="findfdiv">
            <div class="formControls col-3"></div>
            <div class="formControls col-2">
                <span class="select-box">
                    <select class="select" size="1" name="findtaskfromorgid" id="findtaskfromorgid">
                    </select></span>
            </div>
            <div class="formControls col-3">
                <input type="text" class="input-text" placeholder="输入农作物名称" id="findfv1" name="findfv1">
            </div>

            <div class="formControls col-3">
                <button onclick="hcrainpage()" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 查询</button>
            </div>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-5">
            <div class="form form-horizontal">
                <div class="row cl" style="margin-top: 0px">
                    <div class="formControls col-2"></div>
                    <div class="formControls col-2">
                        <input type="text" class="input-text" placeholder="提交说明" id="postdesc" name="postdesc">
                    </div>
                    <label class="form-label col-1">执行人员：</label>
                    <div class="formControls col-2 layui-form">
                        <select name="inoutusernamesel" id='inoutusernamesel' lay-filter="testselect" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                    </div>
                    <div class="formControls col-3">
                        <a href="javascript:;" onclick="savetotaskstre()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 帖码确认</a>
                    </div>
                </div>
            </div>
        </div>
        <div id="hcvueapp" class="mt-5 ml-20">

            <div class="panel panel-default" v-for="site in listinfo">
                <div class="panel-header" style="margin: 0px; padding: 0px;">
                    {{ site.taskfromorgname }}-
                    {{ site.productname }}-
           <!--         -{{ site.taskid }}-->
                    -{{ site.taskworktime }}
               <!--     -{{ site.tasklistid }}-->
                    --包装总数：{{ site.storeall }}  --贴码总数：{{ site.storeallcode }}
                </div>
                <div class="panel-body" style="margin: 0px; padding: 0px;">
                    <table class="table table-border table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>任务信息</th>
                                <th>状态</th>
                                <th>库存(Kg)</th>
                                <th>处理包</th>

                                <th>
                                    <div v-if="site.subinfo2.length >0">包数{{site.subinfo2[0].fv3}}</div>
                                </th>
                                <th>
                                    <div v-if="site.subinfo2.length >1">包数{{site.subinfo2[1].fv3}}</div>
                                </th>
                                 <th>
                                    <div v-if="site.subinfo2.length >2">包数{{site.subinfo2[2].fv3}}</div>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for="(worklist,index) in site.subinfo" v-bind:class="{ success: (worklist.hasoutall<=worklist.storeall), 'warning':worklist.hasoutall>=worklist.storeall }">
                                <td>{{ worklist.taskfromorgname}}-{{ worklist.dkname}}<!---加工：{{ worklist.dataaddtime.Value}}-->-采摘：{{ worklist.taskworktime.Value}}</td>
                                <td>{{ worklist.outstate }}-{{ worklist.productstate }}</td>
                                <td>{{ worklist.storeall }}</td>
                                <td>{{ worklist.storeallbcount }}</td>

                                <td>
                                    <div v-if="site.subinfo2.length >0">
                                        {{ worklist.storefortype1 }}
                                    </div>
                                    <div v-else>没有设置规格</div>
                                </td>
                                <td>
                                    <div v-if="site.subinfo2.length >1">
                                        {{ worklist.storefortype2 }}
                                    </div>
                                </td>
                                 <td>
                                    <div v-if="site.subinfo2.length >2">
                                        {{ worklist.storefortype3 }}
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>

                    <table class="table table-border table-bordered table-hover" style="margin: 0px; padding: 0px;">
                        <thead>
                            <tr>
                                <th>开始编号</th>
                                <th>结束编号</th>
                                <th>数量</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for="(codelist,index) in site.subinfo3">
                                <td>
                                    <input type="text" class="input-text" placeholder="开始编号" v-model="codelist.startCode" onkeyup="onchangeneedtodoid();" />
                                </td>
                                <td>
                                    <input type="text" class="input-text" placeholder="结束编号" v-model="codelist.endCode" onkeyup="onchangeneedtodoid();" />
                                </td>
                                <td>
                                     {{ codelist.codeCount }}  
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="mt-5 row">
                <div id="page1"></div>
            </div>
        </div>
    </div>

    <script type="text/javascript" src="../lib/layui/layui2.js"></script>
    <script type="text/javascript" src="../js/vue.min.js"></script>
    <script>
        var hcvueapp = new Vue({
            el: '#hcvueapp',
            data: {
                listinfo: []
            },
            methods: {
                testc: function (e, e1)
                { console.log(e); console.log(e1); }
            },
            computed: {
                fullName: function () {
                    console.log(this);
                    console.log("执行了computed")
                    return "test";
                }
            }

        })
    </script>
    <script src="../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../lib/layer/1.9.3/layer.js"></script>
    <script type="text/javascript" src="../lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript" src="../lib/My97DatePicker/WdatePicker.js"></script>
    <script src="../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/hcui.js"></script>
    <script type="text/javascript" src="../js/hcui_list.js"></script>

    <script type="text/javascript">
        //基地
        hcdoselbyPost("BranchID as id,BranchName as name", "mrbranch", "type='本部'", "", "", "id", function (data) { SetSelectWithArrayIdName("#findtaskfromorgid", data); });
        var whereaddinfo = "";
        var layui;
        $(function () {
            spsetBaseNoBt("yw_baseinfo", "id", "yw_baseinfo as T", "*", "#tablelist", "sctaskoutstore", "生产任务管理", "sctaskoutstore");
            layui.use(['form'], function () {
                uiform = layui.form();
                //人员下拉加载 
                hcdoselbyPost("empid  as id,concat(depname,'-',empname) as name,empname as username,mobile as  tel,depname as address", "view_user", "branchid='" + HCUser.HCUorg + "'", "", "", "id",
                    function (data) {
                        SetSelectWithArrayIdName("#inoutusernamesel", data);
                        uiform.render();
                    });
            });
            hcrainpage(1);
        });
        function onchangeneedtodoid(htmlid, type) {
            //hcvueapp.listinfo[0].subinfo3
            hcui_ajaxasync = false;
            hcvueapp.listinfo.forEach(function (e) {
                e.storeallcode = 0;
                e.subinfo3.forEach(function (list) {
                    hcapipost("../api/Hcrain/ReSetCodeInfo", list, function (data) {
                        list.codeCount = data.codeCount;
                        e.storeallcode += list.codeCount;
                    });

                   // list.codeCount++;
                });
            });
            hcui_ajaxasync = true;
        }
        //出库处理
        function savetotaskstre() {
            hcui_ajaxasync = false;
            var isPass = false;
            hcapipost("../api/Hcrain/PostCheckCodeListIsOk", hcvueapp.listinfo[0].subinfo3, function (data) {
                if (data != "1") {
                    layer.msg(data, { icon: 2 });
                }
                else { isPass = true; }
            });
            hcui_ajaxasync = true;
            if (isPass == false)
            { return; }

            var needupdate = 0;
            var message = "";//"<input id='ssssssssss'></input>";
            for (var sp in hcvueapp.listinfo) {
                var subinfo = hcvueapp.listinfo[sp].subinfo3;
                console.log(subinfo);
                message += "<br/> " + hcvueapp.listinfo[sp].taskfromorgname + "-" + hcvueapp.listinfo[sp].productname + "[";
                for (var lindex in subinfo) {
                    // TODO 分析是否在库存里TODO
                    //如果不在，返回
                    //如果在，要更新subinfo3信息---因为下面直接使用subinfo3了
                    if (subinfo[lindex].startCode == null || subinfo[lindex].startCode.length <= 0) {
                        console.log("不处理--");
                        continue;
                    }
                    needupdate++;
                    message += "(" + subinfo[lindex].startCode + ")";
                }
                message += "]";
            }
            layer.confirm('确认信息：段数：' + needupdate + message, {
                btn: ["完成贴码", '取消'] //按钮
            }, function () {
                savetotaskstreDo();
            }, function () {

            });
        }
        function savetotaskstreDo() {
            
            var outguid = NewGuid();
            var needupdate = 0;
            var updatecount = 0;
            for (var sp in hcvueapp.listinfo) {
                var subinfo = hcvueapp.listinfo[sp].subinfo3;//段号信息
                for (var lindex in subinfo) {
                    if (subinfo[lindex].startCode == null || subinfo[lindex].startCode.length <= 0) {
                        console.log("不处理--");
                        continue;
                    }
                    //public string startCode { get; set; }
                    //public string endCode { get; set; }
                    //public string codeString { get; set; }
                    //public string startNum { get; set; }
                    //public string endNum { get; set; }
                    //public int codeCount { get; set; }
                    //taskfromorgid-@taskfromorgid,taskid-@taskid,dkid-@dkid,productid-@productid,tasklistid-@tasklistid
                    var addinfo = "outgid%" + outguid
                      + "$outstate%待发货$inouttype%完成贴码"
                      + "$outdesc%" + $("#postdesc").val()
                      //+ "$dkname%" + subinfo[lindex].dkname
                      //+ "$taskid%" + subinfo[lindex].taskid
                      //+ "$taskno%" + subinfo[lindex].taskno
                      //+ "$tasklistid%" + subinfo[lindex].tasklistid
                      //+ "$storehouseid%0$hasoutall%0"
                      //+ "$productid%" + hcvueapp.listinfo[sp].id
                      //+ "$productname%" + hcvueapp.listinfo[sp].fv1
                      //+ "$storeall%" + subinfo[lindex].storeall
                      + "$startcode%" + subinfo[lindex].startCode
                      + "$endcode%" + subinfo[lindex].endCode
                      + "$datafromtable%hsc_task_process_workok"
                      //+ "$datafromkeyid%" + subinfo[lindex].id
                      + "$datafromdesc%加工贴码完成"
                      + "$jjuserid%" + $("#inoutusernamesel").val()//交接人
                     + "$jjusername%" + $("#inoutusernamesel").find("option:selected").text();
                    hcui_ajaxasync = false;
                    console.log(addinfo);
                    //出库处理-这里要禁用异步
                    hcdoadd2017("hsc_task_process_workok_code", addinfo, 1, "{'settype':2,'byfile_name':''}", function (info) {
                        //更新记录--已出库
                        if (info == "ok") {
                            updatecount++;
                            var storelist = hcvueapp.listinfo[sp].subinfo;//列表信息
                            for (var index2 in storelist) {
                                hcdoedit("hsc_task_process_workok", "id", storelist[index2].id, "codegid%" + outguid + "$inoutstorestate%贴码完成", function (info2) {
                                });
                            }
                        }
                        else { layer.msg('处理过程有异常：' + info, { icon: 2 }); }
                    });
                    hcui_ajaxasync = true;
                }
            }
            layer.msg('完成操作，记录数：' + updatecount, { icon: 1 });
            //重新加载 
            if (updatecount > 0) {
                //码段同步库存
                hcui_ajaxasync = false;
                hcapipost("../api/Hcrain/PostOutCodeListIsOk", hcvueapp.listinfo[0].subinfo3, function (data) {
                    if (data != "1") {
                        layer.msg(data, { icon: 2 });
                    }
                });
                hcui_ajaxasync = true;
                hcrainpage(1);
            }

        }
        function hcrainpage(curr) {
            var finddcno = $("#findfv1").val();

            if (finddcno) {
                whereaddinfo = "  productname like '%" + finddcno + "%'";
            }
            else { whereaddinfo = " 1=1"; }

            var sunwhereadd2 = "";
            var sunwhereadd1 = "";
            var findtaskfromorgid = $("#findtaskfromorgid").val();
            if (findtaskfromorgid) {
                sunwhereadd1 = " and taskfromorgid=" + findtaskfromorgid;
                sunwhereadd2 = ",taskfromorgid-" + findtaskfromorgid;
                whereaddinfo += " and taskfromorgid=" + findtaskfromorgid;
            }
            $.ajax({
                type: "post",
                url: "../ashx/spui.ashx",
                data: {
                    "action": "getpageinfo",
                    "pagenow": curr || 1,
                    "pagesize": 1,
                    "select": "t.*,storeallbcount as storeall,0 as storeallcode",
                    "table": "view待贴码分类 as t",
                    "group": "",
                    "having": "",
                    "where": whereaddinfo,//`hsc_task_process_workok`.`taskid`,`hsc_task_process_workok`.`taskworktime`
                    "order": "",
                    "subinfo": "id,taskfromorgid,taskfromorgname,taskid,taskno,tasklistid,productname,dkid,dkname,dataaddtime,storeall,(storeall-hasoutall) as needtodo,CONCAT('needtodo',id) as needtodoid,CONCAT('ggcount1',id) as ggcount1id,CONCAT('ggcount2',id) as ggcount2id,CONCAT('ggallcount',id) as ggallcountid,storefortype1,storefortype2,storefortype3,storefortype1+storefortype2+storefortype3 as storeallbcount,0 as ggallcount,lockcout,hasoutall,outstate,taskworktime,productstate#hsc_task_process_workok#" +
                        "taskfromorgid-@taskfromorgid,taskid-@taskid,dkid-@dkid,productid-@productid,tasklistid-@tasklistid,inoutstorestate-待贴码处理#id#",//当前机构 当前物品
                    "subinfo2": "id,fv1,fv2,fv3,nv1,nv2,nv3#yw_baseinfo#type-7,fv1-@productid#nv2#"//当前机构+7+当前品种
                },
                async: true,
                cache: false,
                error: function (error) {

                },
                success: function (data) {
                    var result = JSON.parse(data);
                    hcvueapp.listinfo = result.data;
                    hcui_ajaxasync = false;
                    //自动分配明细
                    hcvueapp.listinfo.forEach(function (e) {
                        hcapiget("../api/Hcrain/GetOutCodeList", { "gjid": e.taskfromorgid, "spid": e.productid, "count": e.storeallbcount }, function (backdata) {
                            e.subinfo3 = backdata;
                            e.subinfo3.forEach(function (ee) {
                                e.storeallcode = e.storeallcode * 1 + ee.codeCount * 1;
                            });

                        });

                    });





                    ///api/Hcrain/GetOutCodeList?gjid=106&spid=926&count=900
                    //onchangeneedtodoid(1, 1);
                    //计算总量
                    //hcvueapp.listinfo.forEach(function (e) {
                    //    e.subinfo.forEach(function (list) {
                    //        e.storeall = (e.storeall * 1 + (list.storeallbcount * 1)).toFixed(2);
                    //    });
                    //});
                    //if (hcvueapp.listinfo == null || hcvueapp.listinfo.length == 0) {
                    //    result.message = "没有数据";// layer.msg('没有相关数据噢', { icon: 5 });
                    //}
                    //hcvueapp.listinfo.forEach(function (e) {
                    //    e.subinfo.forEach(function (list) {
                    //        list.ggallcount = list.needtodo;
                    //        //e.storeall = e.storeall * 1 + (list.storeall * 1 - list.hasoutall * 1);
                    //    });
                    //});

                    //显示分页
                    laypage({
                        cont: 'page1', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                        pages: result.message || 0, //通过后台拿到的总页数
                        curr: curr || 1, //当前页
                        jump: function (obj, first) { //触发分页后的回调
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                hcrainpage(obj.curr);
                            }
                        }
                    });

                }
            });




        };

        //重新加载-重载
        function findreolad(isback) {
            hcrainpage(1);
        }
    </script>
</body>
</html>
